<?php

/**
 * Description of Abstract
 *
 * @author Admin
 */
class Grabber_Abstract
{
	const NEXT_PARSING_LIST = 1;
	const NEXT_PARSING_NEWS = 1;
	
	protected $_db = null;
	protected $_oNews = null;
	protected $_oParser = null;
	protected $_oComment = null;
	
	protected $_oUsers = null;
	protected $_oLinks = null;
	protected $_oComments = null;
	protected $_oBrowser = null;
	
	protected $_oTranslate = null;

	public function __construct( $db, Parser $oParser, Parser_News $oNews, Parser_Comment $oComment, Browser $oBrowser )
	{
		$this->_db = $db;
		$this->_oNews    = $oNews;
		$this->_oParser  = $oParser;
		$this->_oComment = $oComment;
	
		$this->_oBrowser = $oBrowser;
		$this->_oUsers   = new Users($db);
		$this->_oLinks   = new Links($db);
		$this->_oComments= new Comments( $db );
		
		$this->_oTranslate = new GTranslate();
		
		$this->_init();
	}

	public function _init()
	{
		throw new Exception('Переоприделите метод _init');
	}
	
	protected function _cutSpaces( $text )
	{
		return preg_replace('|>\r*\n*\s*<|iU', '><', $text);
	}
	
	protected function _stripTags( $text )
	{
		return preg_replace('|&.*;|iU', '', $text);
	}
	
	protected function _match( $pattern, $text )
	{
		$matched = array();
		
		if( !preg_match_all('|' . $pattern . '|iU', $text, $matched) )
			return false;
		
		return $matched;
	}
	
	protected function _sql_date( $add_day = false )
	{
		$time = time();
		if( is_numeric( $add_day ) )
		{
			$time += 60 * 60 * 24 * $add_day; 
		}
		
		return date( 'Y-m-d', $time );
	}
	
}

?>